<template>
  <i class="iconfont icon-shoucang" @click="oncollect"> </i>
</template>

<script>
import { collectAPI, oncollectAPI } from "@/api/user.js";
export default {
  data() {
    return {};
  },
  props: {
    // model: {
    //   porp: collected,
    //   event: changecollected,
    // },
    value: {
      type: Boolean,
      require: true,
    },
    artid: {
      type: [Number, String, Object],
      require: true,
    },
  },
  methods: {
    // 收藏/取消收藏点击事件
    async oncollect() {
      if (this.value) {
        try {
          await collectAPI(this.artid);
          this.$emit("input", !this.value);
          this.$toast("取消收藏");
        } catch (err) {
          this.$toast("操作失败，请重试！");
        }
      } else {
        try {
          oncollectAPI(this.artid);
          this.$emit("input", !this.value);
          this.$toast("收藏成功");
        } catch (err) {
          this.$toast("操作失败，请重试！");
        }
      }
    },
  },
};
</script>

<style scoped lang="less">
</style>